package Common_String_API;

import java.util.Random;

//使用String来开发验证码
public class String_Practical_Case2 {
    public static void main(String[] args) {
        System.out.println(createCode(4));
        System.out.println(createCode(6));
    }
    //1.设计一个方法返回指定位数的验证码
    public static String createCode (int n) {
        String code = "";
        String date = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random r = new Random();
        for (int i = 0; i < n; i++) {
            code += date.charAt(r.nextInt(date.length()));
        }
        return code;
    }
}
